const API = require('../settings/api');
const { API_ROOT } = require('../settings');

const getVal = (obj, path) => path.split(".").reduce((o, key) => o && o[key] ? o[key] : null, obj);
const getPath = (url) => url.replace(/\?.*$/, '').replace(`${API_ROOT}/`, '').replace(/\//g, '.');

const getRespSettings = (url) => {
  let path = getPath(url);
  let settings = getVal(API, path);

  return settings ? settings : {
    path: 'common',
    status: 200
  };
};

module.exports = {
  getRespSettings
};